<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="jquery-2.1.4.min.js"></script>
		<style>
			*{font-family: "宋体";font-size: 16px;font-weight: bold;}
			li{line-height: 20px;}
			table{border-collapse: collapse;line-height: 15px;}
			.table1 td:nth-child(1){background: white;width: 150px;height: 20px;border: 1px solid black;}
			.table1 td:nth-child(2){padding-left: 30px;width: 300px;}
			
			.table2 th,.table2 td{width: 60px;padding: 2px;}/*border: 1px solid black;*/
			.table2 th:nth-child(1),.table2 td:nth-child(1){width: auto;}
			tr>td{font-weight: lighter;font-size: 14px;}
			body{margin: 0;}
		</style>
	</head>
	<body>
		<script>
			function _getData(ql){
				return new Promise(function(resolve, reject){
					//通过OData查询字符串获取数据
					Forguncy.getTableDataByOData(ql,
						function(data){
							resolve(data)
						},
					// 获取失败的情况
						function(errorMessage){
							reject("error");
						}
					);
				})
			}
			function getValue(cell){
				var page = Forguncy.Page;
				var textCell = page.getCell(cell);
				return textCell.getValue()
			}
			function dateFtt(fmt, date) { //author: meizz 
				var o = {
					"M+": date.getMonth() + 1, //月份 
					"d+": date.getDate(), //日 
					"h+": date.getHours(), //小时 
					"m+": date.getMinutes(), //分 
					"s+": date.getSeconds(), //秒 
					"q+": Math.floor((date.getMonth() + 3) / 3), //季度 
					"S": date.getMilliseconds() //毫秒 
				};
				if (/(y+)/.test(fmt))
					fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
					if (new RegExp("(" + k + ")").test(fmt))
						fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			}
			Forguncy = window.parent.Forguncy;
			var id = getValue("id")
			var style = getValue("style")
			_getData("Quality_质量报告打印?$select=编号,产品名称,产品来源,生产批号,产品结构,材料名称,测试结论,卷号&$filter=ID eq "+id).then(pr => {
				
				var jg = pr[0].产品结构
				var cl = pr[0].材料名称.split(",")
				var jh = pr[0].卷号.split(",")
				
				var jgT = ""
				cl.forEach(function(v,i){
					jgT+="<tr><td style='background: "+(jg[i]==0 ? "white" : "silver" )+";'></td><td>---------"+v+"</td></tr>"
				})
				
				_getData("Quality_质量报告打印_子表?$select=检验项目,规格值,测试值&$filter=Quality_质量报告打印_ID eq  "+id).then(r => {
					
					var header = 
					"<div class='header'>"
					+ "	<div style='display: flex;align-items: center;justify-content: space-between; border-bottom: double black 5px;padding-bottom: 10px;'>"
					+ "		<img style='width:"+(style==1 ? "120px":"80px")+";' src='imgs/l"+style+".png' />"
					+ "		<span>编号："+pr[0].编号+"</span>"
					+ "	</div>"
					+ "	<div style='font-size: 26px;margin-top: 20px;margin-left: 30px;'>>>>>测试检验报告单</div>"
					+ "	<ul>"
					+ "		<li>产品名称："+pr[0].产品名称.split(",")[0]+"</li>"
					+ "		<li>产品来源："+pr[0].产品来源+"</li>"
					+ "		<li>产品批号："+pr[0].生产批号+"</li>"
					+ "		<li>产品构造："
					+ "			<div style='padding-left: 50px;padding-top: 30px;display: flex;align-items: flex-end;'>"
					+ "				<img src='imgs/00.png' width='64px' style='margin-right: 50px;' />"
					+ "				<table class='table1' cellspacing='0' cellpadding='0'>"+jgT+"</table>"
					+ "			</div>"
					+ "			<div style='height: 1px; border-top: 1px solid black;width: 235px;margin-left: 82px;margin-bottom: 30px;'></div>"
					+ "		</li>"
					+ "	</ul>"
					+ "</div>"
					
					var footer =  
					 "<div class='footer' style='flex:1;'>"
					+ "	<ul>"
					+ "		<li>测试结论："
					+ "			<div style='margin-left: 30px;'>"+pr[0].测试结论+"</div>"
					+ "		</li>"
					+ "	</ul>"
					+ "	<div style='margin-top: 50px;float: right;'>"
					+ "		<div style='line-height: 30px;text-align: center;'><span>"+(style==1 ? "宁波科莱恩新材料科技有限公司" : "天津得丰光电材料技术有限公司")+"</span><br><span>"+dateFtt("yyyy-MM-dd",new Date())+"</span></div>"
					+ "		<img src='"+"imgs/z"+style+".png"+"' style='width: 150px;position: absolute;z-index:-1;margin-top: -110px;margin-left: 45px;' />"
					+ "	</div>"
					+ "</div>"
					
					
					
					var ps = 6
					var pages = jh.length/ps
					pages = Math.ceil(pages)
					
					var body1 =
					"<div class='body'>"
					+ "	<ul>"
					+ "		<li>产品性能："
					+ "			<table class='table2' border='1' style='width: 100%; margin: 20px 0;text-align: center;'>"
					
					var body2 = "</table>"
					+ "		</li>"
					+ "	</ul>"
					+ "</div>"
					
					for (var j = 1; j < pages+1; j++) {
						var jhT = "<tr><th rowspan='2'>项目</th><th rowspan='2'><nobr>规格值</nobr></th><th colspan='"+ps+"'>测试值</th></tr><tr>"
						jh.forEach(function(v,i){
							if((j-1)*ps<i+1 && i<j*ps){
								jhT+="<th>"+v+"</th>"
							}
						})
						jhT+="</tr>"
						
						r.forEach(function(v,i){
							// console.log(v);
							jhT += "<tr><td style='text-align:left'>"+v.检验项目+"</td><td>"+v.规格值+"</td>"
							var csz = v.测试值.split(",")
							csz.forEach(function(v1,i){
								if((j-1)*ps<i+1 && i<j*ps){
									jhT += "<td>"+v1+"</td>"//(v1 ? v1 : '/')
								}
							})
							jhT += "</tr>"
						})
						
						var page = "<br><br><br><br><div style='text-align:center;'>第 "+j+"/"+pages+" 页</div>"
						$("body").append("<div style='display: flex;height: 100vh;flex-direction: column;page-break-after:always;'>"+header+body1 + jhT + body2+footer+page+"</div>")
					}
					
					window.setTimeout(function(){
						window.print()
						$(".FUI-dialog-cover", window.top.document).click()
					},500)
					
				})
			})
		</script>
	</body>
</html>
